package br.com.news.ws;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import br.com.news.utils.database.beans.AcessoNoticiaBean;
import br.com.news.utils.service.exception.ServiceException;


@Path("/acessoNoticia")
public class AcessoNoticiaWs extends GenericWs<AcessoNoticiaBean> {

	@GET
	@Path("/maisLidasDaSemana/{qntNoticias}/{idCategoria}")
	@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
	public String maisLidasDaSemana(@PathParam(value="qntNoticias") int qntNoticias,@PathParam(value="idCategoria") int idCategoria) {
		return listToJson(RmiFactory.getAcessoNoticiaService().maisLidasDaSemana(qntNoticias, idCategoria));
	}
	
	@PUT
	@Path("/insert")
	@Produces("application/json")
	@Consumes("application/json")
	public void save(String json) {
		try {
			AcessoNoticiaBean acessoNoticiaBean = (AcessoNoticiaBean) convertFromJson(json, new AcessoNoticiaBean());
			RmiFactory.getAcessoNoticiaService().save(acessoNoticiaBean);
		} catch (ServiceException e) {
			e.printStackTrace();
		}
	}
	
}
